package com.leetcode.Offer;

public class JZ49 {
    public int nthUglyNumber(int n) {

        int k = 0;//自增数
        int num = 0;//
        int rs = 0;
        while (num < n) {
            k++;
            if (isUgly(k)) {
                num++;
                rs = k;
            }
        }
        return rs;

    }

    private boolean isUgly(int number) {
        while (number % 2 == 0) {
            number /= 2;
        }
        while (number % 3 == 0) {
            number /= 3;
        }
        while (number % 5 == 0) {
            number /= 5;
        }

        return number == 1 ? true : false;
    }

    public static void main(String[] args) {
        System.out.println(new JZ49().nthUglyNumber(1500));
    }
}
